/**
 * @author 黄波
 * 创建日期：2011Sep 6, 2011
 * TODO// N/A
 */
package com.platform.manager.action;

import java.io.PrintWriter;
import java.util.HashMap;
import java.util.List;

import javax.servlet.http.HttpServletResponse;

import net.sf.json.JSONObject;

import org.apache.struts2.ServletActionContext;

import com.platform.manager.bo.PowerModuleBo;
import com.platform.pojo.Module;
import com.platform.pojo.PowerModule;

//根据权限ID，查询对应的模块信息
public class LoadModulesByPowerIdAction extends ManagerSupport {

	private String powerId;
	private List<Module> modules;
	/**
	 * @return the powerId
	 */
	public String getPowerId() {
		return powerId;
	}
	/**
	 * @param powerId the powerId to set
	 */
	public void setPowerId(String powerId) {
		this.powerId = powerId;
	}
	/**
	 * @return the modules
	 */
	public List<Module> getModules() {
		return modules;
	}
	/**
	 * @param modules the modules to set
	 */
	public void setModules(List<Module> modules) {
		this.modules = modules;
	}
	@Override
	public String execute() throws Exception {
		if(powerId == null || powerId.equals("")) {
			return null;
		}
		PowerModuleBo bo = new PowerModuleBo();
		List<PowerModule> powerModules = bo.getModules(powerId);

		HashMap map = new HashMap();
		map.put("powerModules", powerModules);
		JSONObject json = JSONObject.fromObject(map);
		HttpServletResponse response = ServletActionContext.getResponse();
		PrintWriter out = response.getWriter();
		response.setCharacterEncoding("utf-8");
		out.println(json.toString());
		out.flush();
		return null;
	}
	
}
